close all
clc
tic
addpath(genpath(pwd));

if config.if_server
    setenv('LD_LIBRARY_PATH', ['/usr/lib/x86_64-linux-gnu:/usr/local/lib:/usr/lib:' getenv('LD_LIBRARY_PATH')]);
end

config.dataset_root = './demo_dataset/';

config.datasets{1} = initDataset(   ...
    [ config.dataset_root 'vid/GOPR2384_cab/' ] , ...
    [ config.dataset_root 'msk_fg/GOPR2384_cab/' ] );

config.datasets{2} = initDataset(   ...
    [ config.dataset_root 'vid/GOPR2382_cab/' ] , ...
    [ config.dataset_root 'msk_fg/GOPR2382_cab/' ] );

config.temp_root = './temp/';

config.file_list_root = [config.temp_root 'list/'];
config.cluster_list_root = [config.temp_root 'cluster_list/'];
config.sub_model_root = [config.temp_root 'sub_model/'];

config.feature_str = 'l';

config.rep_times = 1;


checkFolder(config.temp_root);
checkFolder(config.sub_model_root);
checkFolder(config.cluster_list_root);
checkFolder(config.file_list_root);

%%


config = getFileLists( config );

save('./temp/config.mat', 'config');

config = writeFileLists( config );

%%

probe_method = @(img)getHist(img);

probe_name = 'hist';

addpath(genpath( './../util/'))

probe = getAppearProbes( config , probe_method );

%%

file_list = getClusterLists( config, probe );

names = writeClusterLists( file_list, config.cluster_list_root, probe_name );
    
save('./temp/names','names');

%%


if config.if_server
    for i = 1:length( names )
        for j = 1 : config.rep_times
            classifier_save_name = [ ...
                config.sub_model_root ...
                names{i}.name '_' ...
                names{i}.affix '_' ...
                'c' num2str( names{i}.cluster_id ) '_' ...
                'rep_' num2str(j)  '_' ];
            commend = [...
                '"./interface/mainInterface" -b ' ...
                '-s "' names{i}.src_name '" ' ...
                '-g "' names{i}.gt_name '" ' ...
                '-v ' config.feature_str ' ' ...
                '-m ' classifier_save_name ];
            system( commend );
            %commend = 
        end
    end
else
    for i = 1:length( names )
        for j = 1 : config.rep_times
            classifier_save_name = [ ...
                config.sub_model_root ...
                names{i}.name '_' ...
                names{i}.affix '_' ...
                'c' num2str( names{i}.cluster_id ) '_' ...
                'rep_' num2str(j)  '_' ];
            commend = [...
                '"./interface/Single.exe" -b ' ...
                '-s "' names{i}.src_name '" ' ...
                '-g "' names{i}.gt_name '" ' ...
                '-v ' config.feature_str ' ' ...
                '-m ' classifier_save_name ];
            system( commend );
            %commend = 
        end
    end
end

